var treeData = [{id:'1',name:'一级解题技巧',data:[{id:'1_1',name:'二级解题技巧',data:[{id:'1_1',name:'二级解题技巧',data:[]},{id:'1_1',name:'二级解题技巧',data:[]},{id:'1_1',name:'二级解题技巧',data:[]},{id:'1_1',name:'二级解题技巧',data:[]}]}]}];
var home = avalon.define("manger_question", function(vm) {
	vm.questions = [{id:1,title:'语文'},{id:2,title:'化学'},{id:3,title:'英语'},{id:4,title:'历史'}];
	vm.knowledgePoint = [{id:1,title:'语文'},{id:2,title:'化学'},{id:3,title:'英语'},{id:4,title:'历史'}];
	vm.problemSolving = [{id:1,title:'语文'},{id:2,title:'化学'},{id:3,title:'英语'},{id:4,title:'历史'}];
	vm.data = treeData;
	vm.currentTagId = "questions";
	vm.subId = vm.questions[0].id;
	
	//显示内容
	vm.pointerMarginTop = 35;
	vm.contentTitle = vm.questions[0].title + '题型';	
	vm.buttonText = "添加题型";
	//点击左侧条目事件
	vm.mangerItemClick = function(){
		//1.得到id
		var itemId = this.getAttribute('data-id');
		vm.subId = itemId;
		//2.根据id给右侧赋值
	};
	//监听itemid变化
	vm.$watch('subId',function(){
		//得到当前的itemdom对象
		var item = $("div.am-active li.active")[0];
		//切换小指针
		vm.pointerMarginTop = item.offsetTop - $(item).parent().parent()[0].scrollTop + 25;
		//变换标题
		var str = ""
		if(vm.currentTagId == "questions"){
			str = "题型";
		}else if(vm.currentTagId == "knowledgePoint"){
			str = "知识点";
		}else{
			str = "解题技巧";
		}
		
		vm.contentTitle = item.innerText + str;
	});
	
	//监听标签变换
	vm.$watch('currentTagId',function(){
		var item = $("div.am-active li.active")[0];
		//变换标题
		var str = ""
		switch(vm.currentTagId){
			case  'questions':
				str = "题型";
				vm.buttonText = '添加题型';
			break;
			case  'knowledgePoint':
				str = "知识点";
				vm.buttonText = '添加知识点';
			break;
			default:
				str = "解题技巧";
				vm.buttonText = '添加解题技巧';
			break;
		}
		vm.contentTitle = item.innerText + str;
	});
});
avalon.scan();
//选项卡切换事件
$('#manger-question-tabs').find('a').on('opened.tabs.amui', function(e) {
	home.currentTagId = $(this).attr('data-tag-id');
	home.subId = home[home.currentTagId][0].id;
	//TODO 切换右边内容
})

function loadInfo(){
	
}

$('div#manger-question-tabs ul.my-panel-ul').on('click',function(){
	
});


//初始化切换条
$('#manger-question-tabs').tabs();
//点击链接冒泡事件
$('.tree li.parent_li > span a').on('click',function(e){
	e.stopPropagation();
});
//展开闭合树状结构
$('.tree li.parent_li > span').on('click', function (e) {
	var children = $(this).parent('li.parent_li').find(' > ul > li');
    if (children.is(":visible")) {
		children.hide('fast');
		$(this).addClass('am-icon-plus-circle').removeClass('am-icon-minus-circle');
	} else {
        children.show('fast');
        $(this).addClass('am-icon-minus-circle').removeClass('am-icon-plus-circle');
    }
    e.stopPropagation();
});